import * as echarts from "echarts"

import chinaMapData from "../data/china.json"

echarts.registerMap("china", chinaMapData)

export default function (el: HTMLElement) {
  const echartsInstance = echarts.init(el)
  const setOptions = (options: any) => {
    echartsInstance.setOption(options)
  }
  // 图表响应式
  window.addEventListener("resize", () => {
    echartsInstance.resize()
  })
  // 折叠侧边栏更新图表尺寸
  const updateSize = () => {
    echartsInstance.resize()
  }
  return {
    echartsInstance,
    setOptions,
    updateSize
  }
}
